﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _5.PropertyChanged
{
    public class Person
    {
        private string firstName;
        private string lastName;
        private DateTime birthDate;
        private readonly string Gender = "F";

        public string FirstName
        {
            get { return this.firstName; }
            set
            {
                if (this.firstName != value)
                {
                    string oldName = this.FirstName;

                    this.firstName = value;
                    OnPropertyChanged("FirstName", oldName, this.firstName);
                }
            }
        }
    
        public string LastName
        {
            get { return this.lastName; }
            set
            {
                if (this.lastName != value)
                {
                    string oldName = this.lastName;

                    this.lastName = value;
                    OnPropertyChanged("LastName", oldName, this.lastName);
                }
            }
        }

        public DateTime BirthDate
        {
            get { return this.birthDate; }
            set
            {
                if (this.birthDate != value)
                {
                    DateTime oldBirthDate = this.birthDate;

                    this.birthDate = value;
                    OnPropertyChanged("BirthDate", oldBirthDate, this.birthDate);
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName, object oldValue, object newValue)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName, oldValue, newValue));
            }
        }
    }
}
